﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using freshflowersHTK.Models;

namespace freshflowersHTK.Controllers
{
    public class UserIndexController : Controller
    {
        private readonly FreshFlowerDbContext _db = new FreshFlowerDbContext();

        //
        // GET: /UserIndex/

        public ActionResult Index(int catId = -1)
        {
            var userIndex = new UserIndex
                                {
                                    Categories = _db.Category.OrderBy(c => c.CategoryName).ToList(),
                                    Catalogs = _db.Catalog.Take(2).ToList()
                                };

            if(catId != -1)
            {
                userIndex.Products = _db.Products.Where(p => string.Compare(p.ProductStatus.ProductStatusLiteral, "A",
                    StringComparison.OrdinalIgnoreCase) == 0 && p.CategoryId == catId).ToList();
            }
            else
            {
                userIndex.Products = _db.Products.Where(p => string.Compare(p.ProductStatus.ProductStatusLiteral, "A",
                    StringComparison.OrdinalIgnoreCase) == 0).ToList();
            }

            return View(userIndex);
        }

    }
}
